added in some optimisations.