completed section of basic algorithm