fixed some bugs, added dirty test