Refactor metric collection