Simplify logic within getMetrics()

A proposal for simplifying the code within `getMetrics()`.
Please, change "key" to...metric?? or some other more specific name.