Fix various bugs, add support for multiple errors

@garyb @joneshf Mind having a look? This is a bunch of work from on a flight, which is why it's quite poorly organized, sorry. If you look at the individual commits, it should make more sense.

Thanks,