made some optimisations to the way classes were being added and removed