creates calculate function