Close connection after sync
Handle zero records to send
Fix arguments passed to WebSocket close
Add and use partial helper function