more robust filename checking
updated comment