How does a judge determine who gets custody