refactor main and added inverse relation