Added more logic to the background tasks