Prune unreferenced nodes