Implemented more queries. Refactored queries and wrote helper functions.