Application State Dependent DB Query / Cleanup