implement cleaner ifs

stack removal and loop for while()
refactor for loop
Revert to recurssion