While iterating over b array I am not getting the right values