Modularize key index search