chaning how the B matrix calculation is done