Refactor type checking in primitives