algorithm implemeted