Fixed unregisterInternal NullPointerException

Added a check for null before trying to reference it.