Refactor apply.sh