Fixed threading bugs and added new threading option