more fixes to ensure that we always generate valid filenames (#440)