Bunch of fixes for setting types.

Fixes #380, fixes #377