Backport various improvements from Tcl 8.5