Fix a bug: it hangs when it removes a share, plus some error handling