Move the code to one place to simplfy the maintenance. Change-Id: Ief075899e7d7f3d383ffbbe03ec75c7d20768cc0