Added error checking to readFile function