Should `if (log)` actually wrap all of this? Looks like some of it has to do with non-log functionality.