Some optimisations for CoreData and refactoring