Move from flask to tornado. Some code refactor.