Changed if statement ordering for less confusion