Fix possible out of bound error