fixed pop function