Add pattern matching to close #1