Thread and SQL changes
Merge pull request #2 from PyroSamurai/Optimize

Thread and SQL changes