Refactored architecture and fixed tests.