refactored to include multiple tables