fixed various bugs with saving
merged