Fixed all errors with writing to log. Parallel loops still do not work correctly.