More bugfixes and unit tests for graph querying