MOD: made the calc function better