added some unit tests, some bugs should be fixed!