fix bug with initialization of n