#11 some code rearrangement