It was due to an incorrect order of function execution. I hard-coded it and lost track of everything when the functions were nested too much.