Improved the scripting factory implementation.