Error handling on save function