refactor to case statement