output into file instead of stdout and small bugfixes