Fixes and improvements for RelayConnection

This fixes issue #98 and makes RelayConnection read/write more efficient.