Added automatic running of queries

Still need to do the TODO's (2)