Incorporated functionality from existing scripts.