refactor create_metric
refactor class Metric
do not use nested function