Fix runtime errors

Signed-off-by: Daniel Thomas <drt24@cam.ac.uk>