Manual merge of some changes of pr332