Added error handling to file parsing