Finished pattern matcher. Requires debugging and additional rules