add lock and fixed localize