Adjusted Q.typeOf to be more robust