Cherrypicked in some fixes