Slight refactoring in preparation for more asynchronous support.