Various bugfixes, better handling of invalid filenames