Applied patch from Matt Kraai which does the following: