Refactor code into common base class

This removed a lot of duplicate code

Change-Id: Ia3cbf39b307c68f02f3534c141753464610d608d
Signed-off-by: Paul Belanger <paul.belanger@polybeacon.com>