Move orphan-handling code down to bottom