Refactor cd scripts