Added index and refactorized