Fixed IndexOufOfBound exception when buffer is empty.