Moved gevent.monkey invocation to the top; miscellaneous fixes