refactor gateway with new gevent and msg-oriented structure