Fixed a few bugs and modify populatePatches

Change-Id: Idfbf77dee8d416be5a4dab4628287eb4ec185a1c