Refactor and simplify metrics collection