fixed some bugs, some more to be done