Upstream merge: possibly fix some head related bugs.