refactored calc functions, simplified and made more functional