Added the new logic of the garbage collector.
Some bugfixes.