Fixing potential issues where invalid parent could be set.