Improve nesting of process_endpoint(). #857