Minor improvements to TCP session handling

Fixes #10