try to optimize database queries