added new output format.
added timeout argument
added shutdown hook to cancel and close statements.