fixing undefined offset issue