Added a while loop and if term