Refactor scripts to adapt to new architecture