fix variable refcnt
test sort and remove unused variable