Properly save and restore proxy type, fixing #191 and #193