adding relations, some refactoring