refactored metrics

@rcrichton please review, this is a new branch based on a more recent version of master
Weird, was this not working before though? Its fine if we leave this as is if you are still experiencing the problem.