adjusted to support natural join