Fix bug with maximum element, and fix bug with ptr to index_array