implement cleaner ifs

stack removal and loop for while()