Fixed implementation of pop and dequeue