Remove unsafe use of array_pop