Change first if conditional to case/when