Rules refactor and unit tests implemented.