Added a simple locking mechanism