Merge "Refactor duplicate code into single function"
am: 1b118b032b

Change-Id: I81baf65489c3c282416ec3903d13f6a94a079e95