Fixed a bug of indexing out the bound of array because rounding.