slight code rearrangement