Improved type inference for instances