refactored metrics

@rcrichton please review, this is a new branch based on a more recent version of master
Minor: tab instead of spaces as used else where in this file.