Merge with upstream, and further fixes