Refactored query related classes (NOTE: still needs corrections)
Added tests (NOTE: incomplete)