corrected index bug