Implemented unit tests. Fixed a pattern matching bug.