refactoring some scripts