Adding some db optimizations