fixed compile error and threading error