refactor code + extend test coverage to 100%