Function to cleanup userdata metadata, clean up code