Refactor background tasks

Refactor background tasks into a simpler model.