CLDIDE-1763: cleanup code, close streams