refactored code, added tests and restructured project structure