Additional fixes suggested by @harding