improved thread safety, refactored a bit, and added table creation