refactored tcp server for less lameness