pop elements from the stack in reverse order bug fixed