Added indexes and made some other small optimizations