Refactor rules and commands/actions.