Porting Original Code as well some clean up #2