refactoring and increased coverage of unit tests