file output and minor division by zero fix