Refactor index func for clarity and fixed for container pt switching. Improved logging and documentation