Fixed API code to work with tornado.