refactored metrics

@rcrichton please review, this is a new branch based on a more recent version of master
Hey @debonair is this change needed? I think it should do the same thing as the above.