Proposed changes

Refactored queries
Removed unused code