advanced calc function