The fix for me was to expliciteley sort the array s probably the order of array was varying.
ksort($this->categories);