Hand refactor - more work on the rules engine