Incorporating Paul's suggested bugfix.