Various unrelated fixes

Various fixes. Review and cherry pick as needed.