refactoring in progress with some unit tests added