Porting original code as well is some clean up #1