added common calculate method.