Add very basic rule validation code. Reorganize some code.