fixed handling files with no newline character at the end