Refactor getting output stream