Working indexing prototype
Code cleaned a bit