Test improvements and fixes