Fixed if statements and added while loops