fix issues regarding file reading. Need more checking...