consolidate and build common functions

Change-Id: I9046cd452dd26015cf338078e2180b8a2b681f9f
Merge "consolidate and build common functions"