This is all going to be completely replaced in the new version. :) Also, I didn't touch this query, just wrapped it in some caching and removed some unused/unnecessary stuff.