fixed a bug when saving the database