Refactored for tornado 4.0.1