added lock guards to all file and client functions