Prepared for Gem. Refined methods for sorting data.