fixed issue where magnitude of M was being set to zero