Implemented minima algorithm. UNTESTED