Refactor of the solution for problem #81