added lock and sleep