correctly handle newline and missing file