Initial refactoring for a GAE compatible version (needs to remove all
thread related code)