Refactor code base, added tests.