fixed some bugs after porting