Reorganize code and fix some coding style violation. Change-Id: Ie5e18cf65ad98f07cd2e4edd8690f53df9bedfeb