Code cleanup and improved PerAppMode

Change-Id: I72c4e9597c5b6420652cacc0975450397fcef4ba
Signed-off-by: klozz <xxx.reptar.rawrr.xxx@gmail.com>