refactor for performance added and in memory index for faster look up