cleared code - optimlisations and conditioning