Code tidy and some minor refactoring

Change-Id: I9ef53c4fe4be17ad09b859583bc401c04f8fa709