more porting and bug fixes