Bug fix pointed out by Andy McNeil