Adopt some (mostly minor) changes from GF branch