Refactoring and cleanups of script runner
Further refactoring and cleanup of script runner