Adding close() method to stream objects