Make match explicit and simplify logic