MODIFIED: database setup moved to thread