refactor and add rule functions