Fixed nested if and nested while statement bugs.