Improved efficiency of solution for #14.