Also write error message to file and remove some commented debug code which looks dirty