Attemt at porting. Not working.