Major code cleanup and alignment

Change-Id: I1dcfbf55926851e137e3ab6e6d59005ad0d1106e