combine the two loops into one

Change-Id: I55d246dc9ae3a585c28e96b29f16707b59f35230