add some locks to prevent any concurrency issues