changed order of if statement to fix issue