using cv instead of lock