Updated app to write to sqlite database at shutdown.