MP algorithm working