Added out of bounds check for pop()