Initial index creation added
A lot of misc code rewritten