refactoring KernelBP code