Changed sql query for main page and added caching