Add set type

This PR adds sane object handling.
Same as for `getref`.