Improve cert fallback logic