Tidying up the logic of the if statement