Added couunting of M and using vectors