Factors out some common syntax and type checking.