rework functions for finding min/max element index. not completely done, some details nmissing.