diff --git a/make_page.sh b/make_page.sh
index 2d5f92a524d37040922bdec1a33f6b1c6ca353b6..d2f2217dc2ad03d5426dc07f5217b784c9d0d75b 100755
--- a/make_page.sh
+++ b/make_page.sh
@@ -1,15 +1,18 @@
 #!/bin/bash
 
+set -e
+
 # Tested on winkel.strw.leidenuniv.nl
 module purge
 module load localhosts
 
-# Uncomment to create new venv
-# python -m venv venv
+# Create venv if it doesn't exist
+[ ! -d "venv" ] && python -m venv venv
 source venv/bin/activate
-
+pip install --upgrade pip
 pip install -r requirements.txt
 
+# Create main webpage
 git pull
 rm -r gallery
 cp -r /home/mcgibbon/public_html/SWIFT/webpage_image_gallery gallery
@@ -20,31 +23,31 @@ rsync -auv compiled/* ../
 
 [ ! -d "swift" ] && git clone "git@gitlab.cosma.dur.ac.uk:swift/swiftsim.git" "swift"
 cd swift
-git checkout master
+[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ] && git checkout master
 git pull
 # Generate read the docs
 cd doc/RTD
-rm -rf build
+[ -d "build" ] && rm -rf build
 make html > docbuild.out 2> docbuild.err
 # Generate onboarding guide
 cd ../onboardingGuide
-rm -rf build
+[ -d "build" ] && rm -rf build
 make latexpdf > onbuild.out 2> onbuild.err
 # Copy both to webpage
 cd ../../..
-rm -rf ../docs/*
+[ -d "../docs" ] && rm -rf ../docs
 cp -r swift/doc/RTD/build/html/ ../docs
 cp swift/doc/onboardingGuide/build/latex/onboarding.pdf ../onboarding.pdf
  
 # Generate read the docs for the zoom branch
 [ ! -d "swift_will" ] && git clone "git@gitlab.cosma.dur.ac.uk:swift/swiftsim.git" "swift_will"
 cd swift_will
-git checkout zoom_docs
+[ "$(git rev-parse --abbrev-ref HEAD)" != "zoom_docs" ] && git checkout zoom_docs
 git pull
 cd doc/RTD
-rm -rf build
+[ -d "build" ] && rm -rf build
 make html > docbuild.out 2> docbuild.err
 cd ../../..
-rm -rf ../docs_will/*
+[ -d "../docs_will" ] && rm -rf ../docs_will
 cp -r swift_will/doc/RTD/build/html/ ../docs_will