Working code with unit tests