resolved segfault by adding a destructor and joining the main thread