fix out of index bug