This certainly needs commenting as to what it is doing and why it needs to be done