Add safety against db inconsistencies