Fix minor bugs, change logging output

Also fix an infinite loop that also locks up the log file at the same
time.