Speed improvements for solution 14.