factor our common code in VPS and improve debug logging