Update from upstream with manual merge of Yasunori Goto's