fix a bug suggested by Wern-Jun Wang.