refactor: move some scripts code around