private function orderByPriority(array $elements)
    {
        // Drop keys from the elements array
        $elements = array_values($elements);
        $length = count($elements);
        for ($i = 0; $i < $length; $i++) {
            for ($j = $i; $j < $length; $j++) {
                $priorityFirst = isset($elements[$i]['priority']) ? (int) $elements[$i]['priority'] : 1;
                $prioritySecond = isset($elements[$j]['priority']) ? (int) $elements[$j]['priority'] : 1;

                if ($priorityFirst < $prioritySecond) {
                    $aux = $elements[$j];
                    $elements[$j] = $elements[$i];
                    $elements[$i] = $aux;
                }
            }
        }

        return $elements;
    }