Lots of refactoring and tests for Ditare module.