Minor refactorings.

There was some unnecessary duplication and allocation.