Optimize index_of_machine function performance