Improved type handling