cleaned up code for B functionality