separate stream finding code from cmd_fclose