add lock mechanism for file operations. add comments.