Fixed indexing bug. Refactoring of Elastic stuff