Fixed a misplaced if statement