Added indexing and sql