Added in tests and logic to handle lost socket connection