Updated script to handle missing fields