Implemented rule matching & execution.

Shuffled code around. Expanded rules data a bit.