A new study from WalletHub has ranked Connecticut as offering its residents one of the best education and health care systems in the nation. However, due to high prices and its shaky economy, the state only landed in the middle of the pack when the personal finance site sorted the states in search of the best place to live.

Connecticut is the 20th-best state to live in according to the study, which took into account affordability, safety, quality of life, education and the strength of the local economy using 51 separate metrics.

The state beat out many popular states like North Carolina, Arizona and California in the overall rankings, but lost out to states like Massachusetts, Minnesota and New York. The study called it the fifth-least affordable state, and ranked its economy 42nd out of all 50 states. However, it offers residents the the fifth-best education and health care system and 18th-best quality of life in the country. The state also has the third-smallest share of its population living in poverty.