Break out helper functions
Add support for pattern matching