Some bugfixes (#576 and #581)