Fix a whole range of issues

see the commit titles / messages for specifics.