Test fixes and a bug fix