updated type checking and casting to be more robust, still need to add support for blobs and files
updated type checking and casting to be more robust, still need to add support for blobs and files