Added a crude locking mechanism