Added garbage collection, bug fixes