Fixed negative index bug