refactoring master detail