Need to write up more detail on this as it's a bit complex.