RF: consolidate variables
RF: rearrange code for consistency
BF: fix logging