modified calculate function template