* orginzed the functions and added some documentation