Delayed writing of log file to end of simulation

Hopefully this will give better performance overall
Added maxPrefixes
Added max processing of prefixes

This will result in a disconnection eventually