refactoring code of Rules module