Finish basic algorithm