Optimizing queries

Eliminated duplicates and set limits to queries.