refactorings to simplify scripts