Incorporate changes from #966