replaced old MaxProduct code with new potential based version