implementation calc function