pop and top functionality done