A few bug fixes