added lock around databased updating function