Copied in from working script.