A few bug fixes and minor changes