Added some code to make it easier to deal with the indexes directly.