replace case match with more idiomatic scala