still have bugs: index out of bound