Refactor matching and captures