Improved type checking