refactored joining DB