Fix potetial negative array index bug.