Output to file
Bugfix + removed debugging