Improved save algorithm