optimize code arrangement