Connection callbacks and other fixes to connection