fixed garbage collection, still does not free everything yet