Should probably factor out these checks.