10x performance improvement replacing indexOf with map