done algorithm