added query for generating links