Updating EM to remove for loops and integrate properly