fixed a bug about array overflow.
added debug mode.