Refactor to encapuslate background code into an object