Fix various integration tests

See detailed description in each individual commit for more info.
patched to master in f3b967f44a927b2dc6dfd30e036f71c452ae11c5 .  @aledsage can you quickly glance at that?