Performance improvements

Mainly:
- Reduced number of queries per page request specifically on front page and profile page
- changed templates, to place javascript at the bottom of the page