Could you add a unit test for this? I would refactor it a little bit to make it more functional and easier to be tested