refactoring and more tests
added TODO