Added error handling to launchThread