added  sort and remove duplicate function