Large refactor to reduce GC