diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index 089f2cf9649da68917bcdd3215606bada923763f..8522f14c9ec902675e9c63d63d4b92ee1c106655 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -30,7 +30,6 @@ from __future__ import print_function, unicode_literals
 
 import re
 import sys
-import traceback
 from builtins import str
 from functools import cmp_to_key
 from hashlib import sha512
@@ -41,8 +40,7 @@ from sys import hexversion
 from tempfile import NamedTemporaryFile
 from warnings import warn
 
-from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
-                                    LIST, REFERENCE, TEXT, is_reference)
+from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, INTEGER, TEXT)
 from caosdb.common.versioning import Version
 from caosdb.common.utils import uuid, xml2str
 from caosdb.configuration import get_config
@@ -63,8 +61,6 @@ from caosdb.exceptions import (AmbiguousEntityError,
                                URITooLongError)
 from lxml import etree
 
-from .datatype import is_reference
-
 _ENTITY_URI_SEGMENT = "Entity"
 
 # importances/inheritance
@@ -644,7 +640,6 @@ class Entity(object):
         if not isinstance(selector, (tuple, list)):
             selector = [selector]
 
-        val = None
         ref = self
 
         # there are some special selectors which can be applied to the
@@ -764,15 +759,14 @@ class Entity(object):
 
         return ret
 
-    def get_errors_deep(self, roots=[]):
+    def get_errors_deep(self, roots=None):
         """Get all error messages of this entity and all sub-entities /
-        parents.
-
-        / properties.
+        parents / properties.
 
         @return A list of tuples. Tuple index 0 contains the error message
                 and tuple index 1 contains the tree.
         """
+        roots = [] if roots is None else roots
         result_list = list()
         ret_self = self.get_errors()
         result_list.extend([
@@ -813,8 +807,7 @@ class Entity(object):
             xml = etree.Element("Entity")
         assert isinstance(xml, etree._Element)
 
-        ''' unwrap wrapped entity '''
-
+        # unwrap wrapped entity
         if self._wrapped_entity is not None:
             xml = self._wrapped_entity.to_xml(xml, add_properties)
 
@@ -970,7 +963,7 @@ class Entity(object):
         # add VALUE
         value = None
 
-        if len(vals):
+        if vals:
             # The value[s] have been inside a <Value> tag.
             value = vals
         elif elem.text is not None and elem.text.strip() != "":
@@ -1258,8 +1251,8 @@ class QueryTemplate():
         self.is_deleted = lambda: False
         self.version = None
 
-    def retrieve(self, strict=True, raise_exception_on_error=True,
-                 unique=True, sync=True, flags=None):
+    def retrieve(self, raise_exception_on_error=True, unique=True, sync=True,
+                 flags=None):
 
         return Container().append(self).retrieve(
             raise_exception_on_error=raise_exception_on_error,
@@ -1404,8 +1397,7 @@ class Parent(Entity):
         if xml is None:
             xml = etree.Element("Parent")
 
-        return super(Parent, self).to_xml(
-            xml=xml, add_properties=add_properties)
+        return super().to_xml(xml=xml, add_properties=add_properties)
 
 
 class _EntityWrapper(object):
@@ -1509,8 +1501,8 @@ class RecordType(Entity):
             # set default importance
             copy_kwargs['inheritance'] = FIX
 
-        return super(RecordType, self).add_property(
-            property=property, value=value, **copy_kwargs)
+        return super().add_property(property=property, value=value,
+                                    **copy_kwargs)
 
     def add_parent(self, parent=None, **kwargs):
         copy_kwargs = kwargs.copy()
@@ -1519,7 +1511,7 @@ class RecordType(Entity):
             # set default importance
             copy_kwargs['inheritance'] = OBLIGATORY
 
-        return super(RecordType, self).add_parent(parent=parent, **copy_kwargs)
+        return super().add_parent(parent=parent, **copy_kwargs)
 
     def __init__(self, name=None, id=None, description=None, datatype=None):  # @ReservedAssignment
         Entity.__init__(self, name=name, id=id, description=description,
@@ -1547,7 +1539,7 @@ class Record(Entity):
             # set default importance
             copy_kwargs['inheritance'] = FIX
 
-        return super(Record, self).add_property(
+        return super().add_property(
             property=property, value=value, **copy_kwargs)
 
     def __init__(self, name=None, id=None, description=None):  # @ReservedAssignment
@@ -1711,7 +1703,7 @@ class File(Record):
             # set default importance
             copy_kwargs['inheritance'] = FIX
 
-        return super(File, self).add_property(
+        return super().add_property(
             property=property, value=value, **copy_kwargs)
 
 
@@ -2248,7 +2240,6 @@ def _deletion_sync(e_local, e_remote):
     if e_local is None or e_remote is None:
         return None
     try:
-        e_remote.get_messages()[('info', 10)]
         _basic_sync(e_local, e_remote)
         e_local.is_valid = lambda: False
         e_local.is_deleted = lambda: True
@@ -2295,11 +2286,11 @@ class Container(list):
         """
 
         if entity in self:
-            super(Container, self).remove(entity)
+            super().remove(entity)
         else:
             for ee in self:
                 if entity == ee.id:
-                    super(Container, self).remove(ee)
+                    super().remove(ee)
 
                     return ee
             raise ValueError(
@@ -2417,13 +2408,13 @@ class Container(list):
         """
 
         if isinstance(entity, Entity):
-            super(Container, self).append(entity)
+            super().append(entity)
         elif isinstance(entity, int):
-            super(Container, self).append(Entity(id=entity))
+            super().append(Entity(id=entity))
         elif hasattr(entity, "encode"):
-            super(Container, self).append(Entity(name=entity))
+            super().append(Entity(name=entity))
         elif isinstance(entity, QueryTemplate):
-            super(Container, self).append(entity)
+            super().append(entity)
         else:
             raise TypeError(
                 "Entity was neither an id nor a name nor an entity." +
@@ -2439,8 +2430,8 @@ class Container(list):
         @return xml element
         """
         tmpid = 0
-        ''' users might already have specified some tmpids. -> look for smallest.'''
 
+        # users might already have specified some tmpids. -> look for smallest.
         for e in self:
             tmpid = min(tmpid, Container._get_smallest_tmpid(e))
         tmpid -= 1
@@ -2659,8 +2650,7 @@ class Container(list):
         # list of remote entities which already have a local equivalent
         used_remote_entities = []
 
-        ''' match by cuid '''
-
+        # match by cuid
         for local_entity in self:
 
             sync_dict[local_entity] = None
@@ -2688,8 +2678,7 @@ class Container(list):
                     if raise_exception_on_error:
                         raise MismatchingEntitiesError(msg)
 
-        ''' match by id '''
-
+        # match by id
         for local_entity in self:
             if sync_dict[local_entity] is None and local_entity.id is not None:
                 sync_remote_entities = []
@@ -2713,8 +2702,7 @@ class Container(list):
                     if raise_exception_on_error:
                         raise MismatchingEntitiesError(msg)
 
-        ''' match by path '''
-
+        # match by path
         for local_entity in self:
             if (sync_dict[local_entity] is None
                     and local_entity.path is not None):
@@ -2743,8 +2731,7 @@ class Container(list):
                     if raise_exception_on_error:
                         raise MismatchingEntitiesError(msg)
 
-        ''' match by name '''
-
+        # match by name
         for local_entity in self:
             if (sync_dict[local_entity] is None
                     and local_entity.name is not None):
@@ -2838,8 +2825,7 @@ class Container(list):
                     ee = EntityError(
                         "This entity has no identifier. It cannot be deleted.", entity)
                     raise TransactionError(ee)
-                else:
-                    entity.is_valid = lambda: False
+                entity.is_valid = lambda: False
 
         if len(id_str) == 0:
             if raise_exception_on_error:
@@ -2910,8 +2896,7 @@ class Container(list):
                             "This entity has no identifier. It cannot be retrieved.",
                             entity)
                         raise TransactionError(ee)
-                    else:
-                        entity.is_valid = lambda: False
+                    entity.is_valid = lambda: False
         else:
             entities_str.append(str(query))
 
@@ -2956,8 +2941,8 @@ class Container(list):
             try:
                 # split up
                 uri1, uri2 = Container._split_uri_string(entities)
-            except ValueError:
-                raise uri_e
+            except ValueError as val_e:
+                raise uri_e from val_e
         c1 = self._retrieve(entities=uri1, flags=flags)
         c2 = self._retrieve(entities=uri2, flags=flags)
         c1.extend(c2)
@@ -3691,10 +3676,10 @@ class Query():
             if len(cresp) > 1 and raise_exception_on_error:
                 raise QueryNotUniqueError(
                     "Query '{}' wasn't unique.".format(self.q))
-            elif len(cresp) == 0 and raise_exception_on_error:
+            if len(cresp) == 0 and raise_exception_on_error:
                 raise EmptyUniqueQueryError(
                     "Query '{}' found no results.".format(self.q))
-            elif len(cresp) == 1:
+            if len(cresp) == 1:
                 r = cresp[0]
                 r.messages.extend(cresp.messages)
 
diff --git a/src/caosdb/exceptions.py b/src/caosdb/exceptions.py
index 55ab8c0d1547a7d78a30efa4c820732dacccd6bc..8c462926ffb44c96a57e5eefdfa7291a51b1bf53 100644
--- a/src/caosdb/exceptions.py
+++ b/src/caosdb/exceptions.py
@@ -57,11 +57,10 @@ class ConfigurationError(CaosDBException):
     """
 
     def __init__(self, msg):
-        super(ConfigurationError, self).__init__(msg +
-                                                 ConfigurationError._INFO)
+        super().__init__(msg + ConfigurationError._INFO)
 
     _INFO = ("\n\nPlease check your ~/.pycaosdb.ini and your $PWD/"
-             ".pycaosdb.ini. Do at least one of them exist and are they correct?")
+             ".pycaosdb.ini. Does at least one of them exist and are they correct?")
 
 
 class HTTPClientError(CaosDBException):
@@ -333,19 +332,17 @@ class EntityHasNoDatatypeError(EntityError):
 
 
 class ConsistencyError(EntityError):
-    """The transaction violates database consistecy."""
+    """The transaction violates database consistency."""
 
 
 class AuthorizationError(EntityError):
     """You are not allowed to do what ever you tried to do.
 
-    Maybe you need more privileges or a user account at all.
-
+    Maybe you need more privileges or a user account.
     """
 
 
 class AmbiguousEntityError(EntityError):
-    """A retrieve of the entity was not possible because there is more
+    """A retrieval of the entity was not possible because there is more
     than one possible candidate.
-
     """