Add null checks on connection objects