Fixed issues with data loss when app is killed