restructure if statements to be less confusing