Very simply, listen to the children. It's not complicated.
Children are more intelligent than they seem, and they will be permanently harmed if they're not heard. Kids will show you that they're hurting by acting out, or they will honestly tell you.
When a custody battle begins the children should have their independent representation in court and should be the first to speak. Do not traumatize them with years of court, and do not scare them into saying the "right" thing. By dragging them through years of court trials they become an object of revenge. Study the child's behavior with each parent. Interview the child by asking NON-leading questions, and then using the information gathered decide which parent should have custody.
PAS (Parental alienation syndrome) is often argued in court. Richard Gardner described the syndrome as “a disturbance in the child who, in the context of divorce, becomes preoccupied with deprecation and criticism of one parent, which denigration is either unjustified and/or exaggerated.” Meaning that the child will naturally say they want to continue living with the parent they already live with due to being influenced or explicitly told to do so by that parent.
However, I believe my situation is good evidence that this is not the case. I lived alone with my father for 7 years, and throughout I said I wanted to live with my mom. Even before I lived with him I protested at the thought of living with him. This, the court attributed to me being influenced by my mother, as my father argued PAS.
Seven years with him, and he still argued that my mother had too much influence over me, and managed to get fewer visitations and less Skype time for me with my mother because I was still saying that I wanted to live with her. I protested going to my father by screaming and kicking at the social workers when he was picking me up from my mom's house. He used this to petition for no visitations at my mother's house. Instead, we could only see each other in a controlled meeting environment for two hours every month, with supervision from the social services. The PAS argument was a tool to prevent my wishes and to quell my voice.
This all could have been prevented if I was just heard, and was represented properly in the court.
links: I highly recommend reading these if you have the time.

https://www.ncsc.org/__data/assets/pdf_file/0014/42152/parental_alienation_Lewis.pdf

https://stopabusecampaign.org/takeaction/family-court-custody-crisis/parental-alienation-syndrome/

