better error handling when saving