clean up and flags settings

Change-Id: I750008d2de1ae1427b7cebef0c67bcaeb782e24f