partially working calculation of n