Refactored some common functions for metric calculations. Updated the documentation.