Fix #740

reorganize the code.
Merge branch 'fix740' of https://github.com/wsantos/tornado into fix740