Fixed wrong placement of if statement