Properly using the document lock