some refactor and increased test coverage