Cleanup. Modified server functionality to properly handle network errors and read/write operations.