finalizing function