fix test bugs and minor cleanup