Fixes tests that are affected by <https://github.com/NixOS/nixpkgs/pull/333744>.
Also do a slight code cleanup.