Add support for custom type handler and handle dict-like objects better