completing the common function v1

trying to build as mush common function as possible to reduce the
repeated code