Changed logic in save function