Tidy up the treatment of newtypes, refactor, and fix Trac #736