Porting code to util file