porting previous extracted code