Refactoring and hql finished