Garbage collection and some code refactoring.