database sql updated to working version. minor tweaks