diff --git a/lib/Thulium/Utilities/Arrays.php b/lib/Thulium/Utilities/Arrays.php
index <HASH>..<HASH> 100644
--- a/lib/Thulium/Utilities/Arrays.php
+++ b/lib/Thulium/Utilities/Arrays.php
@@ -91,15 +91,13 @@ class Arrays
     public static function groupBy(array $elements, $keyFunction, $orderField = null)
     {
         $map = array();
+        if (!empty($orderField)) {
+            $elements = self::orderBy($elements, $orderField);
+        }
         foreach ($elements as $element) {
             $key = Functions::call($keyFunction, $element);
             $map[$key][] = $element;
         }
-        if (!empty($orderField)) {
-            foreach ($map as $key => $value) {
-                $map[$key] = self::orderBy($value, $orderField);
-            }
-        }
         return $map;
     }
Optimized arrays group by sorting.