Refactor and improve deploy script