Some fixes suggested by @pkakelas and @kargig