fix failing tests, a mixture of fixing tests and fixing the underlying code