fix pop function