Fix misplaced if statement