fixed seg faults, but now deadlocking