sorted some of the hql queries code