some code for algorithm