cleaned up reconnect algorithm to improve locking, replace count with bool