Working on max/min detection -- TODO: write unit test