Refactored code into individual metrics for threshold calculation