Patch from Scott McKellar which adds some const-correctness.