Fixes from @mdboom and (hopefully) fix failing test