fix the index out of bound bug
Merge pull request #6 from kuoliu/master

Merging Kuo's changes.