refactor + functions for metrics