fix undefined offset error