now behaves well with fork() and offers a way to automatically reconnet