Refactor garbage collection