- refactored + general algorithm without the rules implementations.