Fixed if and while loop bugs.