Refactored home view and logic
Extracted base query to separate function