fix warnings and leak and threading problem