Custodial parent question

What are the factors a judge considers when determining who will and won’t be the custodial parent in a custody trial? I want to make sure I’m not doing anything that could be perceived badly.

The factors are too numerous and vary from case to case, but the court starts by determining the primary caregiver.