Finish script refactoring