Cherry pick upstreamable changes from master to mer-3.1

Please do not merge using Github interface - it always does a true merge AFAIK and this is not desired here.