Fixed reference Idamax implementation and tests