refactored code and fixed tests
updated build script