fixing potential null pointer in equality check