fixed the indexing bug found by Brad