Fix undefined offset error