Minor modifications. Added utility function index-of-max.