refactored calc