calculate method mostly written