refactor background code