Refactored calculate_change method