Merge back a few bug fixes