few database optimizations