First working query, refactor stuff to analytics module