Some refactoring to use more modular code. Tests fail on this release due to arity mismatch.