refactor case/when statement