csrf fixes, database optimizations