Working on porting algorithm