Fix performance and simplify orphans computation