refactor of queries and post nesting