writen some tests, fixed some bugs