added algorithm to save to txt-file.