Code cleanup and tweaking

Change-Id: I5bf9aa1e2e25b3dbd7f8776981f62e0e9aaca694