Some db performace fixes