edited max_idx.cpp