add better type checking

Add a type checking that check the inner type before returning type.