Refactoring. Fixed problem with index.