clean up code and fix GC