replaced cross product with inner join