Initial refactoring of background tasks