problem 5 solved, extracted some common functions to a package object