Another fix for the IOError: uninitialized stream exception