optimize code structure