#155 database queries improvements