fixing flipped case/when syntax