fixing general calculation funcation