Improve database logic for Home page