Completed kata 8 version optimized for speed.