Further optimizations to database.