fix bug pointed out by Alan