move common functions to proper location