Porting stuffs, plus minor fiexs.