fixed server crashing when tcp client disconnect

with a little bit of love from on('error')
small cleanup