Added fflush before exit so that logs are complete