re-implemented intelligent index selection. fixes #271