index creation
big reorganization of code