refactoring for fork/thread/gevent