Completed merge of commit 0b607e6, with tweaking.