Added Index implementation and fixed some bugs