Finally merged Kerm's changes from Sandpaper.