refactoring and code cleanup
B macro renamed to BP to not collide with variable