added error handling to read_lines