Refactoring: separate modules, rename classes, add test cases