rearrange code from bottom-up to top-down