Cleaning up indexes code a bit