moved a bit of logic to heartbeat class
a trick to detach from child process
split up the client class into 3 parts for readability
more logging