Prevent duplicate record creation on stop

Fix bug where duplicate record is created when:
- app is forced to stop
- saved instance is restored
- forced to stop again

Also fixes extra record creation when editing same record
after a forced stop