define the basic algorithm