fix undefined/null bug