refactoring cypher query generation