Minor refactoring to easily pass around context.