Check the size of the output stream's write buffer before sending data or closing the stream, so as to give the IOLoop a chance to send buffered data.
Remove unused code.
Use command line parser in Tornado.