Refined boundary detection so hierarchy works