updated calculation function