Fixing too many open files - stream and connection closing/not opening