Added relation class and some refactoring