rearranged code structure

rearranged code structure