connection code optimization