fix a bug, now much more powerful