Added background save: when the app moves to an inactive state, it takes the data that it has so far and saves it.