Stabilization and optimization of a two-stage dc SQUID coupled to a high Q resonator