calculate logic