mostly fixed some bugs