Refactor problem19 solution.