Extract metrics calculation in its own class