Added unit test framework, refactored