Fixes #137 and a minor bug which shows the messagebox before actually saving