Fix a few bugs from upstream PR merges