rewrite with master/detail