finished refactoring, added test scripts