refactored handling of calculations