Issue #4: Add a lock around every direct access to the database