added some optimisations