Most of porting of this file done