Key-Index counting algorithm added