cleaning up code a bit
fixing an issue with querying