major changes to function structure of index.py to be more dynamic.