small code refactor for refresh notebooks error handling
write before refresh to avoid lost unsaved data