refactored for script building