refactor the case statement