fixed the bug with garbage collection