memory efficient b and b