Initial import of scripts, refactored to put functions in a common file.