some code rearrangement