Cleanup and finalization, it seems to work now.