final version,all function worked