Reworked type-checking in core