fix undefined bugs