top and pop function modified