Modified error handling for bad filenames. Tested the output against
expected output after recent changes, this version is working.