Some minor code rearrangement