Some database optimizations