Background scripts refactoring. Latest build shows large performance issues.