much faster implementation of garbage collection (just in comment, has to be tested)