Refactored so that locking mechanism can be replaced.