refactored some if statements to make more readable