Refactor into multiple modules; start unit testing