Add callback while saving and fix bugs