Working on #738 Database optimization
Minor fixes