refactored files and added a test and added test::unit
lots of refactoring