Improves error message on bad config; refactors common code