Refactor solution and add test coverage to problem 12