Note that 90% of the red below is because this conditional changes a lot of indentation.