Merged kaus and my code, changed variable names and added write_to_file method