added a lock object to make the API more safe