refactor background extraction