Fixed error in finding render order

 - The error cause elements to be ordered by their ID instead of
   their insert order, causing entirely unexpected and wrong
   rendering results.