Added saving of files and first calculation of sigma. Needs improvement