fix bug, see commit for detail