Does coming out of the closet as gay, lesbian or bisexual actually make one happier? The answer is yes—if you’re in a supportive environment, according to a study by University of Rochester researchers published in Social Psychology and Personality Science.

According to university press materials, scientists anonymously surveyed 161 gay, lesbian and bisexual people, between ages 18 and 65, about their experiences within five contexts: friends, family, coworkers, school peers and religious communities. Participants answered questions regarding how open they were about their sexuality, how much acceptance they felt from others, and how good they felt about themselves in connection with the five groups.

Researchers found that, on average, those who came out in accepting, supportive environments had a greater sense of self-worth and were less likely to suffer from anger or depression. But those who came out in judgmental, controlling environments did not experience the same benefits.

As a result, participants were less likely to come out in controlling and judgmental environments such as religious communities, schools and in the workplace. Findings also showed that neither age nor gender determined who came out. And selecting to disclose in some situations but not in others didn’t affect a person’s mental health, researchers concluded.

“The vast majority of gay people are not out in every setting,” said study coauthor Richard Ryan, PhD, a University of Rochester professor of psychology. “People are reading their environment and determining whether it is safe or not.”

Click here to read about the serious safety issues LGBT youth face when they disclose their sexual identity.