minor refactoring

Organized a few bits of code to minimize GC.