Improved type check