Fix porting stuff. Passes all tests.