Cleanup
Refactor pattern matching