swap if and else branch to make code easier to follow