fix some bugs, add support for setting seed