small script refactoring