Finishing preprocessing algorithm