refactors if statement