added lock to sleep