database optimizations and polish