Bug fix supplied by Niklas Nordin: