gird script refactoring