Initial refactoring.
Now includes App Engine Socket API.