refactor the if-statements