fix incorrect handling of invalid files