Implemented almost all of the queries -- untested though