_pruneexcept function and bugfixes