Fix out of bound bugs.