Refactor deploy script to remove duplication