changed array_pop to array_shift