File handling

Various fixes in file reading and parsing.