refactoring bn.cpp