some logic rearrangements