Separated generic Stream code to a separate method