Big code cleanup

Change-Id: I26e82cf9a0a1f5c602df96196bc5d83a58ac8e99