Moved finalizer handling code to separate files