Could do with some comments about why the code is like this.