Committed first attempt at solving the problem.