added tests, java implementation working
refactored code