Add rules integration module and refactor some stuff