changed the extrema function

ready for testing