sort arrays by size refactored