Added queue for stat handler

We were getting issues with all of the stat handler threads (handler,
sql, etc) running concurrently (multiple instances of same MetaData
key/value pairs).
So I have now implemented a queue so the main thread doesn't wait, but
only there is only one worker thread, avoiding multithreading problems.

Also, added some unique constraints, just to make sure.