added automatic connection checks to avoid dead or stale connections