added a safely_pop_next to ensure only one pop at a time