Code cleanup for metrics.

Note that this code is actually broken :-\ I didn't take the time to either fix
it or rip it out, but this at least improves matters slightly.