Merged from upstream and fixed conflits