BUG: in safe_x_log_x() function, didn't approx log(0) well enough.

Also there's a lot of code re-ordering, white-space fixes etc, but
nothing real.