[connectionagent] crash fix and other optimizations