Added a more generic output stream handling