Fix generating array with unsorted keys