Added unit tests and fixed bugs in problem 49