added output to file + bugfixes