move common functions to main script