set up config, factor out common bits, general tidy