fix placement of if statement