Code refactoring using tornado coroutine