Use urlparse for getting queries. Clean up comments, remove unused imports