Fixed some bugs

Cleaning code the writetofile was gone D=