rearrange some code, define B first