refactored metrics

@rcrichton please review, this is a new branch based on a more recent version of master