Further porting and a few bug fixes