Added error handling when reading from files