fix multiple porting bugs