Fixing a couple of linked bugs and improving test coverage slightly