Final behavioral version with lock function