Reversed an if statement to move the smaller code block to the top