Fixed connection loss issues (but introduces ungraceful termination), and various enhancements/changes to existing code