Fix some out of bound errors