Fixes to work with latest tornado. Few bug fixes