fix a bug subtle but difficult to find :(