refactor metric and add more documentation