code restructure to improve readability

Change-Id: I0337f12870bed9ecb3a7dbf664c0ed3959bf331c