Compiles but a thread is dying prematurely