Replace temp with query and other refactoring

Replace temp with query
Replace string concat with join
Remove unused import
Test User-Agent encoding