Refactor of the code with additional unit test