bug fix and pushing pointers into stack instead of arrays