refactored metrics

@rcrichton please review, this is a new branch based on a more recent version of master
Can you change the functions n this file to use coffee-script rather. This should make the code cleaner. It shouldn't be too difficult to change.